package com.lollipop.schedule.controller;

import com.lollipop.schedule.task.ScheduleTimerTask;
import com.lollipop.schedule.task.ScheduleTriggerTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: J.K
 * @Date: 2022-09-27 15:05
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("schedule")
public class ScheduleController {
    @Resource
    private ScheduleTriggerTask scheduleTriggerTask;

    @Resource
    private ScheduleTimerTask scheduleTimerTask;

    /**
     * 通过trigger设置定时cron
     *
     * @param cron
     * @return
     */
    @GetMapping("updateCronByTrigger")
    public String updateCronByTrigger(String cron) {
        log.info("new cron :{}", cron);
        scheduleTriggerTask.setCron(cron);
        return "trigger ok";
    }

    /**
     * 设置定时timer
     *
     * @param timer
     * @return
     */
    @GetMapping("updateCronByTimer")
    public String updateCronByTimer(Long timer) {
        log.info("new timer :{}", timer);
        scheduleTimerTask.setTimer(timer);
        return "timer ok";
    }
}
